package com.lanjiu.lib.imclient.dto.base;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

/**
 * @description: 数据传输对象(Data Transfer Object)
 * @author: Panwei
 * @date: 2019/11/14 16:11
 */
public abstract class Dto {

    public static <E extends Dto> E fromJson(String json, Class<E> clazz) {
        try {
            return new Gson().fromJson(json, clazz);
        } catch (JsonSyntaxException e) {
            return null;
        }
    }

    public String toJson() {
        return new Gson().toJson(this);
    }

    public abstract Object toProtobuf();
}
